package service;

import java.util.List;

import javax.inject.Inject;

import model.Club;
import repository.ClubRepository;
import repository.ClubSO;

import common.BaseService;

public class ClubService extends BaseService<Club> {
	
	@Inject
	private ClubRepository repository;

	@Override
	public Club get(Long id) {
		return repository.get(id);
	}

	@Override
	public List<Club> getAll() {
		return repository.getAll();
	}
	
	/**
	 * Complete the clubs with its first letters (code or name)
	 * @param so - {@link ClubSO}
	 * @return a {@link List} of {@link Club}
	 */
	public List<Club> completeClub(ClubSO so) {
		return repository.completeClub(so);
	}
	
	/**
	 * Creates a new club
	 * @param club - {@link Club}
	 * @return the new {@link Club}
	 */
	public Club create(Club club) {
		if (club == null) {
			throw new IllegalArgumentException();
		}
		return repository.persist(club);
	}
	
	/**
	 * Delete the club with the given ID
	 * @param id - {@link Long}
	 */
	public void delete(Long id) {
		Club club = repository.get(id);
		repository.delete(club);
	}
	
	/**
	 * Modify the given club.
	 * @param club - {@link Club}
	 * @return club - {@link Club}
	 */
	public Club modify(Club club) {
		repository.merge(club);
		return club;
	}
	
}
